using System;
using System.Diagnostics;

namespace System.IO
{
	public class DebugTextWriter : System.IO.TextWriter
	{
		private System.Text.StringBuilder _Buffer;

		public DebugTextWriter()
		{
			_Buffer = new System.Text.StringBuilder();
		}
		
		public override void Flush()
		{
			Debug.Write(_Buffer.ToString());
			_Buffer.Remove(0,_Buffer.Length);
			Debug.Flush();
		}

		public override void Close()
		{
			this.Flush();
			Debug.Close();
		}

		public override void Write(char value)
		{
			_Buffer.Append(value);
			this.Flush();
		}

		public override void Write(string value)
		{
			_Buffer.Append(value);
			this.Flush();
		}

		public override void Write(char[] buffer, int index, int count)
		{
			_Buffer.Append(buffer,index,count);
			this.Flush();
		}

		public override System.Text.Encoding Encoding
		{
			get
			{
				return System.Text.Encoding.Default;
			}
		}

	}
}
